package org.kjtc.web;

import org.kjtc.mapper.TimerMapper;
import org.kjtc.service.LogService;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimerTask;

public class StatisticalWorkTask extends TimerTask {

    private TimerMapper taskMapper;
    private LogService logService;

    public StatisticalWorkTask(TimerMapper taskMapper, LogService logService) {
        this.taskMapper = taskMapper;
        this.logService = logService;
    }
    public void run(){
        System.out.println("["+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+"]:   插入BackLog数据定时任务启动成功(每日)");
        logService.insertLog("开始统计每人工作任务","");
        int num=taskMapper.insertBackLogDataEverybody();
        if(num <= 0){
            logService.insertLog("统计每人工作任务失败","");
            throw new RuntimeException("["+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+"]:   插入BackLog数据失败(每日)");
        }else{
            System.out.println("["+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+"]:   插入BackLog数据成功(每日)");
            logService.insertLog("统计每人工作任务成功","");
        }
        System.out.println("["+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+"]:   插入BackLog数据定时任务执行结束(每日)");
    }

}
